package com.perfma.xtest.request;

import java.io.*;

/**
 *
 *
 * @author: junhui.si
 * @date: 2024-04-30 15:10
 **/
public class JmxRequest2 {

    public static void main(String[] args) {
        String inputFilePath = "/Users/sijunhui/Downloads/1-jmeter/超多请求.jmx";  // 输入文件路径
        String outputFilePath = "/Users/sijunhui/Downloads/1-jmeter/超多请求2.jmx";  // 输出文件路径

        String pattern = "HTTP-xxx-1";

        try {
            // 读取输入文件
            BufferedReader reader = new BufferedReader(new FileReader(inputFilePath));
            StringBuilder sb = new StringBuilder();
            String line;
            while ((line = reader.readLine()) != null) {
                sb.append(line).append(System.lineSeparator());
            }
            reader.close();

            // 对文本进行替换
            String text = sb.toString();
            StringBuilder result = new StringBuilder();

            int count = 1;
            int lastIndex = 0;
            while (true) {
                int index = text.indexOf(pattern, lastIndex);
                if (index == -1) {
                    break;
                }
                result.append(text, lastIndex, index);
                result.append(pattern).append("_").append(count);
                lastIndex = index + pattern.length();
                count++;
            }
            result.append(text.substring(lastIndex));

            // 将结果写入输出文件
            BufferedWriter writer = new BufferedWriter(new FileWriter(outputFilePath));
            writer.write(result.toString());
            writer.close();

            System.out.println("转换完成！");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
